package com.example.mongodb1;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.index.Index;
import org.springframework.data.mongodb.core.index.IndexOperations;

@SpringBootTest
public class MongodbIndex {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Test
    void createIndex() {
        IndexOperations indexOperations = mongoTemplate.indexOps("1_form");
        indexOperations.ensureIndex(new Index().on("username", Sort.Direction.ASC).named("username_index"));
    }

}
